<?php 
/**
 * Class description
 *
 * @since 30 мая 2010
 * @author diotheos
 */
class Zend_View_Helper_FormAggregator extends Zend_View_Helper_FormElement {
	protected $_html = '';
	private $_parameters = array(
	   'wrapper' => array(
	       'tag' => 'div',
	       'label' => array(
	           'tag' => 'div',
	           'attr' => array(
	               'class' => 'asasas'
	           ),
               'place' => 'prepend'
	       ),
	       'attr' => array('class'=>'dododo')
	   ),
	   'options' => array(
	       'labelPosition'=> 'before'
	   ),
	   'elements' => array(
		   'from'  => array(
	           'type' => 'text',
	           'label'=> array(
	               'text' => 'От'
	           ),
	           'description' => '',
	           'options' => array()
	       ),
	       'to' => array(
	           'type' => 'select',
	           'label'=> array(
	               'text' => 'До'
	           ),
	           'options' => array()
	       )
	   )	   
	);
	/**
	 * Function description
	 *
	 * @since 30 мая 2010
	 * @author diotheos
	 */
	public function formAggregator($name, $value = null, $attribs = null) {
//        if(null === $attribs){
        	$attribs = $this->_parameters;
//        }
        $wrapperHead = $wrapperTail = $wrapperAttr = $wrapperLegend = '';
        if($attribs['wrapper']){
        	if(is_array($attribs['wrapper']['attr'])){
        		foreach($attribs['wrapper']['attr'] as $attr=>$value){
        			$wrapperAttr .= " $attr = '$value'";
        		}
        	}
        	$wrapperHead = '<'.$attribs['wrapper']['tag'].$wrapperAttr.'>';
        	$wrapperTail = '</'.$attribs['wrapper']['tag'].'>';
        }
		$this->_html .= $wrapperHead;
		
		
        foreach($attribs['elements'] as $elName=>$elParams){
        	$classNameSuffixed = "Zend_View_Helper_Form".ucfirst($elParams['type']);
        	$classMainFunction = 'form'.ucfirst($elParams['type']);
        	$$elName = new $classNameSuffixed();
        	$$elName->setView($this->view);
        	$this->_html .= $$elName->$classMainFunction($name. "[$elName]",'',$elParams['options']);
        }
        
        
        $this->_html .= $wrapperTail;
        return $this->_html;
    }
    
    /**
     * Function description
     * 
     * @since 4 июня 2010
     * @author diotheos
     * @return void
     */
    private function _create(){
    	
    }
}